package com.diancan.web.controller.dc;

import java.util.List;

import com.diancan.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.diancan.common.annotation.Log;
import com.diancan.common.enums.BusinessType;
import com.diancan.dc.domain.DcEvaluationInfo;
import com.diancan.dc.service.IDcEvaluationInfoService;
import com.diancan.common.core.controller.BaseController;
import com.diancan.common.core.domain.AjaxResult;
import com.diancan.common.utils.poi.ExcelUtil;
import com.diancan.common.core.page.TableDataInfo;

/**
 * 评价Controller
 *
 * @author dc
 * @date 2021-12-30
 */
@Controller
@RequestMapping("/dc/evaluationInfo")
public class DcEvaluationInfoController extends BaseController {
    private String prefix = "dc/evaluationInfo";

    @Autowired
    private IDcEvaluationInfoService dcEvaluationInfoService;

    @RequiresPermissions("dc:evaluationInfo:view")
    @GetMapping()
    public String evaluationInfo() {
        return prefix + "/evaluationInfo";
    }

    /**
     * 查询评价列表
     */
    @RequiresPermissions("dc:evaluationInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DcEvaluationInfo dcEvaluationInfo) {
        dcEvaluationInfo.setUserName(ShiroUtils.getLoginName());
        startPage();
        List<DcEvaluationInfo> list = dcEvaluationInfoService.selectDcEvaluationInfoList(dcEvaluationInfo);
        return getDataTable(list);
    }

    /**
     * 导出评价列表
     */
    @RequiresPermissions("dc:evaluationInfo:export")
    @Log(title = "评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DcEvaluationInfo dcEvaluationInfo) {
        List<DcEvaluationInfo> list = dcEvaluationInfoService.selectDcEvaluationInfoList(dcEvaluationInfo);
        ExcelUtil<DcEvaluationInfo> util = new ExcelUtil<DcEvaluationInfo>(DcEvaluationInfo.class);
        return util.exportExcel(list, "评价数据");
    }

    /**
     * 新增评价
     */
    @GetMapping("/add")
    public String add(String id, ModelMap mmap) {
        mmap.put("orderId", id);
        return prefix + "/add";
    }

    /**
     * 新增保存评价
     */
    @RequiresPermissions("dc:evaluationInfo:add")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DcEvaluationInfo dcEvaluationInfo) {
        return toAjax(dcEvaluationInfoService.insertDcEvaluationInfo(dcEvaluationInfo));
    }

    /**
     * 修改评价
     */
    @RequiresPermissions("dc:evaluationInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        DcEvaluationInfo dcEvaluationInfo = dcEvaluationInfoService.selectDcEvaluationInfoById(id);
        mmap.put("dcEvaluationInfo", dcEvaluationInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存评价
     */
    @RequiresPermissions("dc:evaluationInfo:edit")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DcEvaluationInfo dcEvaluationInfo) {
        return toAjax(dcEvaluationInfoService.updateDcEvaluationInfo(dcEvaluationInfo));
    }

    /**
     * 删除评价
     */
    @RequiresPermissions("dc:evaluationInfo:remove")
    @Log(title = "评价", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dcEvaluationInfoService.deleteDcEvaluationInfoByIds(ids));
    }
}
